home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Sim68000 / cpu / m68000.hxx < prev    next >
Encoding:
Text File  |  1995-07-26  |  10.9 KB  |  269 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // $Id: m68000.hxx,v 1.5 1995/06/30 00:08:20 bmott Exp $
  3. ///////////////////////////////////////////////////////////////////////////////
  4. // m68000.hxx
  5. //
  6. // Motorola 68000 microprocessor class
  7. //
  8. // Sim68000 "Motorola 68000 Simulator"
  9. // Copyright (c) 1993
  10. // By: Bradford W. Mott
  11. // October 31,1993
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // $Log: m68000.hxx,v $
  15. // Revision 1.5  1995/06/30  00:08:20  bmott
  16. // Modified declaration for ServiceInterrupts()
  17. //
  18. // Revision 1.4  1995/01/13  00:34:01  bmott
  19. // Changed the in_register argument from the ComputeEffectiveAddress
  20. // member function
  21. //
  22. // Revision 1.3  1994/09/22  00:12:26  bmott
  23. // Add BREAK instruction method
  24. //
  25. // Revision 1.2  1994/08/22  07:31:49  bmott
  26. // Removed const from the register information structure
  27. //
  28. // Revision 1.1  1994/02/18  20:04:40  bmott
  29. // Initial revision
  30. //
  31. ///////////////////////////////////////////////////////////////////////////////
  32.  
  33. #ifndef M68000_HXX
  34. #define M68000_HXX
  35.  
  36. #include <iostream.h>
  37. #include "BasicCPU.hxx"
  38. #include "BasicDevice.hxx"
  39.  
  40. // Instruction Size Constants
  41. #define BYTE   0
  42. #define WORD   1
  43. #define LONG   2
  44.  
  45. // Set Condition Code operation types
  46. #define ADDITION    0
  47. #define SUBTRACTION 1
  48. #define OTHER       2
  49.  
  50. class m68000;
  51.  
  52. // Register information structure
  53. struct RegisterData {
  54.   char* name;
  55.   unsigned long mask;
  56.   char* description;
  57. };
  58.  
  59. // Pointer to an instruction execution routine
  60. typedef int (m68000::*ExecutionPointer)(int, String&, int);
  61.  
  62. // DecodeEntry structure for the Decode Table
  63. struct DecodeEntry {
  64.   unsigned int mask;
  65.   unsigned int signature;
  66.   ExecutionPointer execute;
  67. };
  68.  
  69.  
  70.  
  71. class m68000 : public BasicCPU {
  72.   private:
  73.     // Number of registers in the cpu
  74.     const int number_of_registers;
  75.  
  76.     // Array of static information for each register 
  77.     static RegisterData register_data[];
  78.  
  79.     // Pointer to an array of values for each register
  80.     unsigned long *register_value;
  81.  
  82.     // Indices into the register arrays (Note: D0-D7-A0-A7' must be sequential)
  83.     const int D0_INDEX;
  84.     const int A0_INDEX;
  85.     const int USP_INDEX;
  86.     const int SSP_INDEX;
  87.     const int PC_INDEX;
  88.     const int SR_INDEX;
  89.  
  90.     // Status Register masks
  91.     const unsigned long C_FLAG;         // Carry
  92.     const unsigned long V_FLAG;         // Overflow
  93.     const unsigned long Z_FLAG;         // Zero
  94.     const unsigned long N_FLAG;         // Negative
  95.     const unsigned long X_FLAG;         // Extend
  96.     const unsigned long I0_FLAG;        // Interrupt Mask Level
  97.     const unsigned long I1_FLAG;        // Interrupt Mask Level
  98.     const unsigned long I2_FLAG;        // Interrupt Mask Level
  99.     const unsigned long S_FLAG;         // Supervisory
  100.     const unsigned long T_FLAG;         // Trace Mode
  101.  
  102.     // Execution Return Constants
  103.     const int EXECUTE_OK;
  104.     const int EXECUTE_PRIVILEGED_OK;
  105.     const int EXECUTE_BUS_ERROR;
  106.     const int EXECUTE_ADDRESS_ERROR;
  107.     const int EXECUTE_ILLEGAL_INSTRUCTION;
  108.  
  109.     // Processor state (NORMAL_STATE, HALT_STATE, or STOP_STATE, BREAK_STATE)
  110.     unsigned int processor_state;
  111.  
  112.     // Procesor state constants
  113.     const unsigned int NORMAL_STATE;
  114.     const unsigned int HALT_STATE;
  115.     const unsigned int STOP_STATE;
  116.     const unsigned int BREAK_STATE;
  117.  
  118.  
  119.     static DecodeEntry decode_table[];
  120.     static ExecutionPointer *decode_cache_table;
  121.  
  122.     // Decode the given instruction
  123.     ExecutionPointer DecodeInstruction(int opcode);
  124.  
  125.     // Routines to simulate the execution of the instruction
  126.     int ExecuteABCD(int opcode, String& description, int trace);
  127.     int ExecuteADD(int opcode, String& description, int trace);
  128.     int ExecuteADDA(int opcode, String& description, int trace);
  129.     int ExecuteADDI(int opcode, String& description, int trace);
  130.     int ExecuteADDQ(int opcode, String& description, int trace);
  131.     int ExecuteADDX(int opcode, String& description, int trace);
  132.     int ExecuteAND(int opcode, String& description, int trace);
  133.     int ExecuteANDI(int opcode, String& description, int trace);
  134.     int ExecuteANDItoCCR(int opcode, String& description, int trace);
  135.     int ExecuteANDItoSR(int opcode, String& description, int trace);
  136.     int ExecuteASL(int opcode, String& description, int trace);
  137.     int ExecuteASR(int opcode, String& description, int trace);
  138.     int ExecuteBRA(int opcode, String& description, int trace);
  139.     int ExecuteBREAK(int opcode, String& description, int trace);
  140.     int ExecuteBSR(int opcode, String& description, int trace);
  141.     int ExecuteBcc(int opcode, String& description, int trace);
  142.     int ExecuteBit(int opcode, String& description, int trace);
  143.     int ExecuteCHK(int opcode, String& description, int trace);
  144.     int ExecuteCLR(int opcode, String& description, int trace);
  145.     int ExecuteCMP(int opcode, String& description, int trace);
  146.     int ExecuteCMPA(int opcode, String& description, int trace);
  147.     int ExecuteCMPI(int opcode, String& description, int trace);
  148.     int ExecuteCMPM(int opcode, String& description, int trace);
  149.     int ExecuteDBcc(int opcode, String& description, int trace);
  150.     int ExecuteDIVS(int opcode, String& description, int trace);
  151.     int ExecuteDIVU(int opcode, String& description, int trace);
  152.     int ExecuteEOR(int opcode, String& description, int trace);
  153.     int ExecuteEORI(int opcode, String& description, int trace);
  154.     int ExecuteEORItoCCR(int opcode, String& description, int trace);
  155.     int ExecuteEORItoSR(int opcode, String& description, int trace);
  156.     int ExecuteEXG(int opcode, String& description, int trace);
  157.     int ExecuteEXT(int opcode, String& description, int trace);
  158.     int ExecuteILLEGAL(int opcode, String& description, int trace);
  159.     int ExecuteJMP(int opcode, String& description, int trace);
  160.     int ExecuteJSR(int opcode, String& description, int trace);
  161.     int ExecuteLEA(int opcode, String& description, int trace);
  162.     int ExecuteLINK(int opcode, String& description, int trace);
  163.     int ExecuteLSL(int opcode, String& description, int trace);
  164.     int ExecuteLSR(int opcode, String& description, int trace);
  165.     int ExecuteMOVE(int opcode, String& description, int trace);
  166.     int ExecuteMOVEA(int opcode, String& description, int trace);
  167.     int ExecuteMOVEM(int opcode, String& description, int trace);
  168.     int ExecuteMOVEP(int opcode, String& description, int trace);
  169.     int ExecuteMOVEQ(int opcode, String& description, int trace);
  170.     int ExecuteMOVEUSP(int opcode, String& description, int trace);
  171.     int ExecuteMOVEfromSR(int opcode, String& description, int trace);
  172.     int ExecuteMOVEtoCCR(int opcode, String& description, int trace);
  173.     int ExecuteMOVEtoSR(int opcode, String& description, int trace);
  174.     int ExecuteMULS(int opcode, String& description, int trace);
  175.     int ExecuteMULU(int opcode, String& description, int trace);
  176.     int ExecuteNBCD(int opcode, String& description, int trace);
  177.     int ExecuteNEG(int opcode, String& description, int trace);
  178.     int ExecuteNEGX(int opcode, String& description, int trace);
  179.     int ExecuteNOP(int opcode, String& description, int trace);
  180.     int ExecuteNOT(int opcode, String& description, int trace);
  181.     int ExecuteOR(int opcode, String& description, int trace);
  182.     int ExecuteORI(int opcode, String& description, int trace);
  183.     int ExecuteORItoCCR(int opcode, String& description, int trace);
  184.     int ExecuteORItoSR(int opcode, String& description, int trace);
  185.     int ExecutePEA(int opcode, String& description, int trace);
  186.     int ExecuteRESET(int opcode, String& description, int trace);
  187.     int ExecuteROL(int opcode, String& description, int trace);
  188.     int ExecuteROR(int opcode, String& description, int trace);
  189.     int ExecuteROXL(int opcode, String& description, int trace);
  190.     int ExecuteROXR(int opcode, String& description, int trace);
  191.     int ExecuteRTE(int opcode, String& description, int trace);
  192.     int ExecuteRTR(int opcode, String& description, int trace);
  193.     int ExecuteRTS(int opcode, String& description, int trace);
  194.     int ExecuteSBCD(int opcode, String& description, int trace);
  195.     int ExecuteSTOP(int opcode, String& description, int trace);
  196.     int ExecuteSUB(int opcode, String& description, int trace);
  197.     int ExecuteSUBA(int opcode, String& description, int trace);
  198.     int ExecuteSUBI(int opcode, String& description, int trace);
  199.     int ExecuteSUBQ(int opcode, String& description, int trace);
  200.     int ExecuteSUBX(int opcode, String& description, int trace);
  201.     int ExecuteSWAP(int opcode, String& description, int trace);
  202.     int ExecuteScc(int opcode, String& description, int trace);
  203.     int ExecuteTAS(int opcode, String& description, int trace);
  204.     int ExecuteTRAP(int opcode, String& description, int trace);
  205.     int ExecuteTRAPV(int opcode, String& description, int trace);
  206.     int ExecuteTST(int opcode, String& description, int trace);
  207.     int ExecuteUNLK(int opcode, String& description, int trace);
  208.     int ExecuteInvalid(int opcode, String& description, int trace);
  209.  
  210.     int ExecuteBusError(int opcode, String& description, int trace);
  211.     int ExecuteAddressError(int opcode, String& description, int trace);
  212.  
  213.     // Helpful routines for the 'Execute' instruction routines
  214.     int ComputeEffectiveAddress(unsigned long& address,
  215.                                 int& in_register,
  216.                                 String &description, int mode_register,
  217.                                 int size, int trace);
  218.     int Peek(unsigned long address, unsigned int& value, int size);
  219.     int Poke(unsigned long address, unsigned int value, int size);
  220.     unsigned int SignExtend(unsigned int value, int size);
  221.     void SetConditionCodes(unsigned int src, unsigned int dest,
  222.                            unsigned int result, int size,
  223.                            int operation, int mask);
  224.     void ClearConditionCodes(int mask);
  225.     int  CheckConditionCodes(int code, String& mnemonic, int trace);
  226.     void SetRegister(int register_number, unsigned int value, int size);
  227.     int  ProcessException(int vector);
  228.  
  229.     long my_interrupt;
  230.     BasicDevice* my_device;
  231.  
  232.   public:
  233.     m68000(AddressSpace*);         // The constructor
  234.     virtual ~m68000();             // The destructor
  235.  
  236.     // Execute a single instruction
  237.     const char* ExecuteInstruction(String& trace_record, int trace_flag);
  238.  
  239.     // Service pending interrupts, set serviceFlag to true iff we
  240.     // are had to service an interrupt
  241.     int ServiceInterrupts(int& serviceFlag);
  242.  
  243.     // Handle an interrupt request from a device
  244.     void InterruptRequest(BasicDevice* device, int level);
  245.  
  246.     // Preform a system reset
  247.     void Reset();
  248.  
  249.     // Return the name of the program counter register
  250.     char* const NameOfProgramCounter()
  251.     { return ("PC"); }
  252.  
  253.     // Return the value of the program counter register
  254.     unsigned long ValueOfProgramCounter();
  255.  
  256.     // Set the named register to the given value
  257.     void SetRegister(String name, String hex_value);
  258.  
  259.     // Not keeping any statistics
  260.     void ClearStatistics()
  261.     {}
  262.  
  263.     void BuildRegisterInformationList(RegisterInformationList*);
  264.  
  265.     void BuildStatisticalInformationList(StatisticalInformationList*);
  266. };
  267.  
  268. #endif
  269.